//
//  test_invoke.h
//  TestMac
//
//  Created by 小星星吃KFC on 2021/6/4.
//

#import <Foundation/Foundation.h>



//NSProxy 就是NSProxy不是继承NSProject,在运行过程中可以伪装成任何对象.其实也是消息转发
static void test_invoke(void){
    
    Person *person = Person.alloc.init;
    SEL mySelector = NSSelectorFromString(@"eat:");
    //    SEL mySelector = @selector(eat:);
    NSMethodSignature * sig = [Person instanceMethodSignatureForSelector: mySelector];//
    NSInvocation * myInvocation = [NSInvocation invocationWithMethodSignature:sig];//调用方法信号
    [myInvocation setTarget:person];// 设置目的实例
    [myInvocation setSelector:mySelector];// 设立方法
    NSString *arg1 = @"吃";
    [myInvocation setArgument: &arg1 atIndex: 2];
    [myInvocation invoke]; //调用方法
    ///完成调用设置调用返回值
    NSString *ret = @"";
    [myInvocation getReturnValue: &ret]; //完成调用设置调用返回值
    NSLog(@"返回值 = %@",ret);
    
}




